<template>
  <div>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="180px"
      class="demo-ruleForm"
      :inline="true"
    >
      <el-form-item label="组织编码" prop="scenNum">
        <el-input v-model="ruleForm.scenNum"></el-input>
      </el-form-item>
      <el-form-item label="组织名称" prop="scenName">
        <el-input v-model="ruleForm.scenName"></el-input>
      </el-form-item>
      <el-form-item label="上级组织">
        <el-select v-model="ruleForm.firId">
          <div v-for="item in optionData" :key="item.firId">
            <el-option :label="item.firName" :value="item.firId"></el-option>
          </div>
        </el-select>
      </el-form-item>
      <el-form-item label="排序">
        <el-input v-model="ruleForm.orderss"></el-input>
      </el-form-item>

      <el-form-item label="组织说明">
        <el-input type="textarea" v-model="ruleForm.depText"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="addDep()">添加</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { getList, userAdd } from "@/api/userApi";
export default {
  data() {
    return {
      ruleForm: {
        scenName: "",
        scenNum: "",
        firId: "",
        orderss: "",
        depText: "",
        updateTime: "",
        createTime: "",
      },
      rules: {
        scenName: [{ required: true, message: "必填项", trigger: "blur" }],
        scenNum: [{ required: true, message: "必填项", trigger: "blur" }],
      },
      optionData: [],
    };
  },
  created() {
    this.selectList();
  },
  methods: {
    addDep() {
      userAdd(this.ruleForm).then((res) => {
        this.$router.push("/list");
      });
    },
    //获取列表
    selectList() {
      getList().then((res) => {
        this.optionData = res.data.data;
        console.log(res.data.data);
      });
    },
  },
};
</script>
